﻿using System.Data;
using Loki.Data;
using Luna.Data.Mappers;

namespace Luna.Data.Project.Mappers
{
    public class ProjectDataMapper : LunaEntityMapper<ProjectData, IProjectData>
    {
        public const string COL_CODE = "Code";
        public const string COL_NAME = "Name";
        public const string COL_DESCRIPTION = "Description";
        public const string COL_ALLOCATED = "Budget";
        public const string COL_OUTCOME = "StartDate";
        public const string COL_INCOME = "EndDate";

        protected override void LoadCoreData(IProjectData P_Entity, IDataRecord P_Record)
        {
            P_Entity.Name = P_Record.GetString(COL_NAME);
            P_Entity.Code = P_Record.GetString(COL_CODE);
            P_Entity.Description = P_Record.GetString(COL_DESCRIPTION);
            P_Entity.Budget = P_Record.GetDecimal(COL_ALLOCATED);
            P_Entity.Start = P_Record.GetDate(COL_OUTCOME);
            P_Entity.End = P_Record.GetDate(COL_INCOME);
        }

        protected override void MapSaveParameters(IDatabaseCommand P_Command, IProjectData P_Entity)
        {
            P_Command.AddParameter(COL_CODE, P_Entity.Code);
            P_Command.AddParameter(COL_NAME, P_Entity.Name);
            P_Command.AddParameter(COL_DESCRIPTION, P_Entity.Description);
            P_Command.AddParameter(COL_ALLOCATED, P_Entity.Budget);
            P_Command.AddParameter(COL_OUTCOME, P_Entity.Start);
            P_Command.AddParameter(COL_INCOME, P_Entity.End);
            P_Command.AddParameter(COL_ID, P_Entity.PK);
        }
    }
}
